<?php

namespace easydis\APSBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class PlanifierType extends AbstractType
{   
    
    private $idgs = '1';

    public function __construct($idgs){
        $this->idgs = $idgs;
    }
    
    
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $opt = $this->idgs;
        $builder
            ->add('salarie', 'hidden')
            ->add('gs', 'hidden', array('mapped' => false))
            ->add('date', 'text');
            $builder->add('plagehoraire', 'entity', array('class' => 'easydisAPSBundle:PlageHoraire','property' => 'lib', 
                        'query_builder' => function($repository) use (&$opt){
                        return $repository->createQueryBuilder('ph')
                                ->join('ph.groupe_service', 'gs')
                                ->where('gs.id=:idgs')
                                ->setParameter('idgs',$opt);
                        }));
            $builder->add('poste', 'entity', array('class' => 'easydisAPSBundle:Poste','property' => 'lib', 
                        'query_builder' => function($repository) use (&$opt){
                        return $repository->createQueryBuilder('po')
                                ->join('po.section', 'sc')
                                ->join('sc.service', 'se')
                                ->join('se.groupe_services', 'gs')
                                ->where('gs.id=:id')
                                ->setParameter('id',$opt);
                        }));
    }
    
    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'easydis\APSBundle\Entity\Planifier'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'easydis_apsbundle_planifier';
    }
}
